package base

/*
* @author: hjz
* @time: 2025/4/26 18:38
* @ 每次遇到重复的字符时,左边界移动到上次记录位置+1，并且每次移动的左边界要比现在左边界大
 */
// "abcabcbb"

func lengthOfLongestSubstring(s string) int {
	m := make(map[rune]int, len(s)>>1)
	l := 0
	res := 0
	for r, v := range s {
		if j, ok := m[v]; ok && j >= l {
			l = j + 1
		}
		m[v] = r
		res = maxInt(r-l+1, res)
	}
	return res
}
